package View;
import javax.swing.JLabel;

import java.awt.Rectangle;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.Font;
import java.io.Serializable;


/** this class provide the GUI window in order to configure the connection to DB server */
public class ConfigurationView extends JFrame implements Serializable  {
	private static final long serialVersionUID = 42L;

	/** Required buttons */
	private JLabel ipLabel = null;
	private  JTextField ipField = null;

	private JTextField portField = null;
	private JLabel portLabel = null;

	private JLabel dbpasswordLabel = null ;
	private JTextField dbpasswordField = null;

	private JLabel userNameLabel = null ;
	private JTextField userNameField = null;

	private JButton okButton;
	private JButton exitButton;

	/**This is the default constructor*/
	public ConfigurationView() 
	{
		super();
		initialize();
	}

	/**This method initializes Connection form*/
	private void initialize() {

		ipLabel = new JLabel();
		ipLabel.setFont(new Font("Tahoma", Font.PLAIN, 13));
		ipLabel.setBounds(new Rectangle(20, 88, 113, 19));
		ipLabel.setText("Ip :");

		ipField = new JTextField(16);
		ipField.setBounds(new Rectangle(143, 89, 127, 17));

		portLabel = new JLabel();
		portLabel.setFont(new Font("Tahoma", Font.PLAIN, 13));
		portLabel.setBounds(new Rectangle(20, 113, 113, 18));
		portLabel.setText("Port :");

		portField = new JTextField(10);
		portField.setBounds(new Rectangle(143, 114, 127, 18));

		dbpasswordLabel = new JLabel();
		dbpasswordLabel.setFont(new Font("Tahoma", Font.PLAIN, 13));
		dbpasswordLabel.setBounds(new Rectangle(20, 31, 113, 17));
		dbpasswordLabel.setText("Password :");

		dbpasswordField = new JTextField(20);		
		dbpasswordField.setBounds(new Rectangle(143, 31, 127, 17));

		userNameLabel = new JLabel();
		userNameLabel.setFont(new Font("Tahoma", Font.PLAIN, 13));
		userNameLabel.setBounds(new Rectangle(20, 59, 113, 18));
		userNameLabel.setText("User Name :");

		userNameField = new JTextField(20);		
		userNameField.setBounds(new Rectangle(143, 61, 127, 17));

		okButton = new JButton("Connect");
		okButton.setFont(new Font("Tahoma", Font.BOLD, 13));
		exitButton = new JButton("Exit");
		exitButton.setFont(new Font("Tahoma", Font.BOLD, 13));
		okButton.setBounds(79, 155, 100, 30);
		exitButton.setBounds(211, 155, 100, 30);

		userNameField.setText("root");
		dbpasswordField.setText("1234");
		ipField.setText("localhost");
		portField.setText("5555");

		this.setLocationRelativeTo(null); 
		this.setBounds(450, 200,372, 240);
		this.setResizable(false);
		this.setTitle("Configuration");

		getContentPane().setLayout(null);
		getContentPane().add(ipLabel, null);
		getContentPane().add(ipField, null);
		getContentPane().add(portLabel, null);
		getContentPane().add(portField, null);
		getContentPane().add(dbpasswordLabel, null);
		getContentPane().add(dbpasswordField, null);

		getContentPane().add(userNameLabel, null);
		getContentPane().add(userNameField, null);

		getContentPane().add(okButton, null);
		getContentPane().add(exitButton, null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}


	/**add listeners to the buttons*/
	public void addConfigListeners(ActionListener actionListener)
	{
		okButton.addActionListener(actionListener);
		exitButton.addActionListener(actionListener);
	}

	/**
	 * @return text field ipField
	 */
	public  JTextField getIpField() 
	{
		return ipField;
	}
	/**
	 * @return Label ipLabel
	 */
	public JLabel getIpLabel() 
	{
		return ipLabel;
	}
	/**
	 * @return text field portField
	 */
	public JTextField getPortField() 
	{
		return portField;
	}
	/**
	 * @return Label portLabel
	 */
	public JLabel getPortLabel() 
	{
		return portLabel;
	}
	/**
	 * @return text field userNameField
	 */
	public JTextField getUserNameField() 
	{
		return userNameField;
	}
	/**
	 * @return text field dbpasswordField
	 */
	public JTextField getDbpasswordField() 
	{
		return dbpasswordField;
	}
	/**
	 * @return Label field dbpasswordLabel
	 */
	public JLabel getDbpasswordLabel() 
	{
		return dbpasswordLabel;
	}

	/**
	 * @return button okButton
	 */
	public JButton getOkButton() 
	{
		return okButton;
	}
	/**
	 * @return button exitButton
	 */
	public JButton getExitButton() 
	{
		return exitButton;
	}

	/** show and hide window functions */
	public void showWindow()
	{
		setVisible(true);
	}
	public void hideWindow()
	{
		setVisible(false);
	}
}



